package com.mdxl.controller;

import com.mdxl.Entity.City;
import com.mdxl.redis.RedisDao;
import com.mdxl.service.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/redis")
public class RedisController {
    private static Logger logger= LoggerFactory.getLogger(RedisController.class);
    @Autowired
    RedisDao redisDao;
    @Autowired
    RedisService redisService;
    //视图操作 ValueOperations  ListOperations、SetOperations、ZSetOperations 和 HashOperations



    @RequestMapping("/xianshi")
    public String testRedis(){
        redisDao.setKey("name","forezp");
        redisDao.setKey("age","11");
        logger.info(redisDao.getValue("name"));
        logger.info(redisDao.getValue("age"));
        return "oo";
    }
    @RequestMapping(value = "/add/{id}/{name}",method = RequestMethod.POST)
    public void add(@PathVariable("id") String id,@PathVariable("name") String name){
        redisService.add(id, name);
    }
    @PostMapping("/update/{id}/{name}")
    public void update(@PathVariable("id") String id,@PathVariable("name") String name){
        redisService.update(id,name);
    }
    @DeleteMapping("/delete/{id}/{name}")
    public void delete(@PathVariable("id") String id){
        redisService.delete(id);
    }
    @GetMapping("/gain/{id}/{name}")
    public String gain(@PathVariable("id") String id){
        return redisService.get(id);
    }
    @PostMapping("/addcity")
    public void addCity(){
        City city =new City();
        city.setCityName("baoding");
        city.setDescription("文明树新风");
        city.setPrivinceId(0312);
        redisService.addCity(city);
    }
    @GetMapping("/getcity/{id}")
    public City getCity(@PathVariable("id")int id){
        return redisService.getCity(id);
    }

}
